package io.wit.modules.sys.controller;

import io.wit.config.ConfigFile;
import io.wit.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;

/**
 * Controller公共组件
*/
public abstract class AbstractController {
	
	protected SysUserEntity getUser() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	protected Long getUserId(){
		return getUser().getUserId();
	}

	protected String getUserName(){
		return getUser().getUsername();
	}

	protected Long getDeptId() {
		return getUser().getDeptId();
	}

	protected Long getSubjectId() {
		return getUser().getSubjectId();
	}

	protected Long getRoleId(){
        final Long roleId = getUser().getRoleId();
        return (roleId == null) ? -1 :roleId;
	}

	protected Integer getOptions(){
        final Integer options = getUser().getOptions();
        return (options == null) ? -1 :options;
	}

    protected boolean filterPrivilege(final int roleId){
        if(ConfigFile.superUser.equals(getUserName())){
            return true;
        }
        return getRoleId() == roleId;
    }
}